package formBean;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class RegistrationForm extends FormBean{

	private String email;
	private String password;
	private String firstName;
	private String lastName;
	private String passwordConfirmation;
	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}
	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}
	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}
	/**
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}
	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}
	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	/**
	 * @param firstName the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	/**
	 * @param lastName the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();

		if (email == null || email.length() == 0) {
			errors.add("email is required");
		}else{
			if (email.length() < 5 || !email.contains(".") || !email.contains("@")){
				errors.add("Invalid email format");
			}
			
			if(email.contains("<") || email.contains(">") ||  email.contains("/") ||  email.contains("\\") || email.contains("\"") || email.contains("'")){
				errors.add("Invalid email format");
			}
		}
		
		if (password == null || password.length() == 0) {
			errors.add("Password is required");
		}else{
			if(password.contains("<") || password.contains(">") ||  password.contains("/") ||  password.contains("\\") || password.contains("\"") || password.contains("'")){
				errors.add("Invalid email format");
			}
		}
		
		if(passwordConfirmation == null || passwordConfirmation.length() == 0){
			errors.add("Password confimation is required");
		}
		
		if(passwordConfirmation != null && passwordConfirmation.length() > 0 && password != null && password.length() > 0 && !password.equals(passwordConfirmation)){
			errors.add("Password confirmation doesn't match");
		}
		
		if(firstName == null || firstName.length() == 0){
			errors.add("First Name is required");
		}else{
			if(firstName.contains("<") || firstName.contains(">") ||  firstName.contains("/") ||  firstName.contains("\\") || firstName.contains("\"") || firstName.contains("'")){
				errors.add("Invalid first name format");
			}
		}
		
		if(lastName == null || lastName.length() == 0){
			errors.add("Last name is required");
		}else{
			if(lastName.contains("<") || lastName.contains(">") ||  lastName.contains("/") ||  lastName.contains("\\") || lastName.contains("\"") || lastName.contains("'")){
				errors.add("Invalid first name format");
			}
		}
		
		return errors;
	}
	
	/**
	 * @return the passwordConfirmation
	 */
	public String getPasswordConfirmation() {
		return passwordConfirmation;
	}
	/**
	 * @param passwordConfirmation the passwordConfirmation to set
	 */
	public void setPasswordConfirmation(String passwordConfirmation) {
		this.passwordConfirmation = passwordConfirmation;
	}
}
